<?php
    get_header();
    $allsearch = new WP_Query("s=$s");
    $count = $allsearch->post_count;
    global $wp_query;
    $ncount = $wp_query->found_posts
?>
<!-- 列表模块 -->
<div class="main-container">
    <div class="wrap">
        <p class="page-title search-stats">与“<span><?php echo get_search_query(); ?></span>”相关内容共搜出<?php echo $ncount?>条结果</p>
        <div class="clearfix">
            <div class="main-block">
                <ul class="main-common-list">
                    <?php
                    query_posts($query_string . '&orderby=date&posts_per_page=25');
                        while(have_posts()) {
                            the_post();
                    ?>
                    <li>
                        <a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a>
                        <span class="date"><?php the_time('Y-m-d'); ?></span>
                    </li>
                    <?php
                        }
                        wp_reset_query();
                    ?>
                    
                </ul>
                <div class="pagination" id="pagination">
                <?php spar_pagenavi($wp_query, 25); ?>
                
                </div>
            </div>
            <div class="sidebar">
                <div class="notice-mod hot-article-mod floor">
                    <div class="head-type02">
                        <h2>热门文章</h2>
                    </div>
                    <div class="article-main">
                        <?php
                            $queryArg = array(
                                'showposts' => 7,
                                "meta_key" => "post_views_count",
                                "orderby" => "meta_value_num",
                                "order" => "DESC",
                                "cat" => 6
                            );
                            query_posts($queryArg);
                            if (have_posts()) {
                                the_post();
                            
                        ?>
                        <div class="article-first clearfix">
                            <a class="img-block" href="<?php the_permalink(); ?>" title="">
                                <?php the_post_thumbnail(array(120, 73)); ?>
                            </a>
                            <div class="art-right">
                                <h3><a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a></h3>
                                <p class="date"><?php the_time('Y-m-d'); ?></p>
                            </div>
                        </div>
                        <?php
                        }
                        ?>
                        <ul>
                            <?php
                            for ($i = 0; $i < 7; $i++) {
                                if (have_posts()) {
                                    the_post();
                                ?>
                            <li>
                                <i></i>
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </li>
                                <?php
                                } else {
                                    break;
                                }
                            }
                            ?>
                        </ul>
                    </div>
                </div>
                <?php get_template_part('template-parts/sidebar-topic', get_post_format()); ?>
            </div>
        </div>
    </div>
</div>
<?php
    get_footer();
?>
<script>
(function() {
    var pageTotal = parseInt($('.pagination-total em').text());
    $('.pagination-go').on('click', function() {
        var val = parseInt($(this).siblings('input').val());
        if (isNaN(val) || val < 1 || val > pageTotal) {
            alert('请输入1~' + pageTotal + '之间的页码数');
            return;
        }
        page_links = $("#pagination a")
        .eq(1)
        .attr("href"); //从页码列表中获取任意一个链接,此处获取第一个链接
      go_link = page_links.replace(
        /\/page\/([0-9]{1,})/g,
        "/page/" + val
      ); //将页码数字替换
      location.href = go_link; //跳转
    }); 
})();
</script>